import gcj02BD09 from "./gcj02BD09.js"
const openMapLocation = function(lat,lng){
	console.log(lat,lng,"lat,lng")
	let locat = gcj02BD09.transformFromBaiduToGCJ(Number(lat),Number(lng))
	console.log(locat,"locatlocatlocatlocat")
	uni.openLocation({
		latitude:locat.latitude,
		longitude:locat.longitude,
		success(res) {
			console.log(res,"success")
		},
		fail(e) {
			// uni.showToast({
			// 	title:e,
			// 	icon:'none',
			// 	duration:6000
			// })
			console.log(e)
		}
	})
}
const chooseLocation = function(lat,lng,callback){
	uni.showLoading({
		title:'打开地图中...'
	})
	console.log(lat,lng)
	uni.chooseLocation({
		latitude:lat,
		longitude:lng,
		success(res) {
			let obj = gcj02BD09.transformFromGCJToBaidu(res.latitude,res.longitude)
			res.latitude = obj.latitude
			res.longitude = obj.longitude
			callback(res)
		},
		complete() {
			uni.hideLoading()
		}
	})
}
const myGetLocation = function(callback,isChoose=true,showLoading=true){
	if (showLoading) {
		uni.showLoading({
			title:"获取定位中..."
		})
	}
	uni.getLocation({
		type:"gcj02",
		success(res) {
			if(isChoose){
				chooseLocation(res.latitude,res.longitude,callback)
			}else{
				callback({lat:res.latitude,lng:res.longitude})
			}
		},
		fail(e) {
		},
		complete() {
			uni.hideLoading() 
		}
	})
}
export default {
	myGetLocation,chooseLocation,openMapLocation
}